package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "菜品管理")
@RequestMapping("/admin/dish")
public class DishController {
    @Autowired
    private DishService dishService;

    /**
     * 新增菜品
     *
     * @param dto
     * @return
     */
    @PostMapping
    public Result add(@RequestBody DishDTO dto) {

        return dishService.add(dto);
    }

    /**
     * 菜品分页查询
     *
     * @param dto
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("菜品分页查询")
    public Result<PageResult> page(DishPageQueryDTO dto) {
        return dishService.pageQuery(dto);
    }

    /**
     * 删除菜品
     *
     * @param ids
     * @return
     */
    @DeleteMapping
    @ApiOperation("删除菜品")
    public Result delete(@RequestParam List<Long> ids) {
        return dishService.delete(ids);

    }

    /**
     * 根据id查询菜品(数据回显)
     *
     * @param id
     * @return
     */
    @GetMapping("{id}")
    @ApiOperation("根据id查询菜品")
    public Result getById(@PathVariable Long id) {
        return dishService.getById(id);
    }


    /**
     * 修改菜品
     *
     * @return
     */
    @PutMapping
    @ApiOperation("修改菜品")
    public Result updateDish(@RequestBody DishDTO dto) {
        return dishService.updateDish(dto);
    }

    /**
     * 根据分类id查询菜品
     * @param categoryId
     * @return
     */

    @GetMapping("/list")
    public Result<List<Dish>> list(Long categoryId) {
        return dishService.list(categoryId);

    }

    /**
     * 菜品的状态
     * @param status
     * @param id
     * @return
     */

    @PostMapping("/status/{status}")
    public Result status(@PathVariable Integer status, Long id){
        return  dishService.status(status,id);

    }


}
